<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-CN">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="条件语句While 123456789101112131415// MARK: - While &amp;gt;&amp;gt; do whilelet num = -1repeat &amp;#123;    print(&quot;num is \(num)&quot;)&amp;#125;while num &amp;gt; 0let names = [&quot;Anna&quot;,&quot;Alex&quot;,&quot;Brian&quot;,&quot;jack&quot;]let range = 0...3for">
<meta property="og:type" content="article">
<meta property="og:title" content="swift5">
<meta property="og:url" content="http://yoursite.com/2019/06/24/swift5/index.html">
<meta property="og:site_name" content="Erhqe">
<meta property="og:description" content="条件语句While 123456789101112131415// MARK: - While &amp;gt;&amp;gt; do whilelet num = -1repeat &amp;#123;    print(&quot;num is \(num)&quot;)&amp;#125;while num &amp;gt; 0let names = [&quot;Anna&quot;,&quot;Alex&quot;,&quot;Brian&quot;,&quot;jack&quot;]let range = 0...3for">
<meta property="og:locale" content="zh-CN">
<meta property="og:updated_time" content="2019-08-23T03:24:58.286Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="swift5">
<meta name="twitter:description" content="条件语句While 123456789101112131415// MARK: - While &amp;gt;&amp;gt; do whilelet num = -1repeat &amp;#123;    print(&quot;num is \(num)&quot;)&amp;#125;while num &amp;gt; 0let names = [&quot;Anna&quot;,&quot;Alex&quot;,&quot;Brian&quot;,&quot;jack&quot;]let range = 0...3for">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2019/06/24/swift5/"/>





  <title>swift5 | Erhqe</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-CN">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Erhqe</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            Categories
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2019/06/24/swift5/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Erhqe">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/10.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Erhqe">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">swift5</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-06-24T09:07:48+08:00">
                2019-06-24
              </time>
            

            

            
          </span>

          

          
            
              <span class="post-comments-count">
                <span class="post-meta-divider">|</span>
                <span class="post-meta-item-icon">
                  <i class="fa fa-comment-o"></i>
                </span>
                <a href="/2019/06/24/swift5/#comments" itemprop="discussionUrl">
                  <span class="post-comments-count valine-comment-count" data-xid="/2019/06/24/swift5/" itemprop="commentCount"></span>
                </a>
              </span>
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="条件语句"><a href="#条件语句" class="headerlink" title="条件语句"></a>条件语句</h4><p><strong>While</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - While &gt;&gt; do while</span></span><br><span class="line"><span class="keyword">let</span> num = -<span class="number">1</span></span><br><span class="line"><span class="keyword">repeat</span> &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"num is \(num)"</span>)</span><br><span class="line">&#125;<span class="keyword">while</span> num &gt; <span class="number">0</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> names = [<span class="string">"Anna"</span>,<span class="string">"Alex"</span>,<span class="string">"Brian"</span>,<span class="string">"jack"</span>]</span><br><span class="line"><span class="keyword">let</span> range = <span class="number">0</span>...<span class="number">3</span></span><br><span class="line"><span class="keyword">for</span> i <span class="keyword">in</span> range &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"name is \(names[i])"</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> name <span class="keyword">in</span> names[<span class="number">0</span>...<span class="number">3</span>] &#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"name is \(name)"</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<a id="more"></a>
<p><strong>单侧区间</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 单侧区间  [2...] 从2开始尽可能的远</span></span><br><span class="line"><span class="keyword">for</span> name <span class="keyword">in</span> names[...<span class="number">2</span>]&#123;</span><br><span class="line">    <span class="built_in">print</span>(name) <span class="comment">// "Anna","Alex","Brian"</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> name <span class="keyword">in</span> names[<span class="number">2</span>...]&#123;</span><br><span class="line">    <span class="built_in">print</span>(name) <span class="comment">// "Brian","jack"</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> name <span class="keyword">in</span> names[..&lt;<span class="number">2</span>]&#123;</span><br><span class="line">    <span class="built_in">print</span>(name) <span class="comment">// "Anna","Alex"</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> range1 = ...<span class="number">5</span></span><br><span class="line">range1.<span class="built_in">contains</span>(<span class="number">7</span>)   <span class="comment">//false</span></span><br><span class="line">range1.<span class="built_in">contains</span>(<span class="number">5</span>)   <span class="comment">// true</span></span><br><span class="line">range1.<span class="built_in">contains</span>(-<span class="number">3</span>)  <span class="comment">// true</span></span><br></pre></td></tr></table></figure>
<p><strong>在字符串中</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> stringRange = <span class="string">"a"</span>...<span class="string">"f"</span>;</span><br><span class="line">stringRange.<span class="built_in">contains</span>(<span class="string">"b"</span>)   <span class="comment">// true</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">let</span> stirngRange2 = <span class="string">"cc"</span>...<span class="string">"ff"</span>  <span class="comment">// cc,cd,ce,cf &gt;&gt; cz &gt;&gt; da &gt;&gt; ff</span></span><br><span class="line">stirngRange2.<span class="built_in">contains</span>(<span class="string">"cd"</span>) <span class="comment">//  true</span></span><br><span class="line">stirngRange2.<span class="built_in">contains</span>(<span class="string">"ca"</span>) <span class="comment">//  false</span></span><br></pre></td></tr></table></figure>
<p><strong>ASCII</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - ASCII 码表上</span></span><br><span class="line"><span class="keyword">let</span> asciiRange = <span class="string">"\(0)"</span>...<span class="string">"~"</span></span><br><span class="line">asciiRange.<span class="built_in">contains</span>(<span class="string">"c"</span>) <span class="comment">//  true</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// MARK: - 带间隔的区间云算函数  从2开始 到 10 间隔 2</span></span><br><span class="line"><span class="keyword">for</span> time <span class="keyword">in</span> <span class="built_in">stride</span>(from: <span class="number">2</span>, to: <span class="number">10</span>, by: <span class="number">2</span>)&#123;</span><br><span class="line">    <span class="built_in">print</span>(time)  <span class="comment">// 打印结果 2 4 6 8</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h6 id="For-In"><a href="#For-In" class="headerlink" title="For In"></a>For In</h6><figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 带间隔的区间云算函数  从2开始 到 10 间隔 2</span></span><br><span class="line"><span class="keyword">for</span> time <span class="keyword">in</span> <span class="built_in">stride</span>(from: <span class="number">2</span>, to: <span class="number">10</span>, by: <span class="number">2</span>)&#123;</span><br><span class="line">    <span class="built_in">print</span>(time)  <span class="comment">// 打印结果 2 4 6 8</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - Where 在for循环中Where决定了要不要进循环  整数相加</span></span><br><span class="line"><span class="keyword">var</span> numbers = [<span class="number">10</span>,<span class="number">20</span>,-<span class="number">10</span>,-<span class="number">20</span>,<span class="number">30</span>,-<span class="number">30</span>]</span><br><span class="line"><span class="keyword">var</span> sum = <span class="number">0</span></span><br><span class="line"><span class="keyword">for</span> num <span class="keyword">in</span> numbers <span class="keyword">where</span> num &gt; <span class="number">0</span>&#123;</span><br><span class="line">    sum += num</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 标签语句 作用面循环的continue 最外面循环也管用</span></span><br><span class="line">outer: <span class="keyword">for</span> i <span class="keyword">in</span> <span class="number">1</span>...<span class="number">4</span>&#123;</span><br><span class="line">    <span class="keyword">for</span> k <span class="keyword">in</span> <span class="number">1</span>...<span class="number">4</span>&#123;</span><br><span class="line">        <span class="keyword">if</span> k == <span class="number">3</span> &#123;</span><br><span class="line">            <span class="keyword">continue</span> outer</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> i == <span class="number">3</span>&#123;</span><br><span class="line">            <span class="keyword">break</span> outer</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="built_in">print</span>(<span class="string">"i = \(i),k = \(k)"</span>)</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h6 id="Switch"><a href="#Switch" class="headerlink" title="Switch"></a>Switch</h6><figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - switch Case 和 Default 下面必须有一行代码, break 默认可以省略 , fallthrough 表示case穿透,Swift的Switch必须考虑到所有可能性,如果不考虑的话需要些Default</span></span><br><span class="line"><span class="keyword">var</span> num1 = <span class="number">1</span></span><br><span class="line"><span class="keyword">switch</span> num1 &#123;</span><br><span class="line"><span class="keyword">case</span> <span class="number">1</span>:</span><br><span class="line">    <span class="keyword">fallthrough</span></span><br><span class="line"><span class="keyword">case</span> <span class="number">2</span>:</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"number is 1,2"</span>)</span><br><span class="line"><span class="keyword">default</span>:</span><br><span class="line">    <span class="keyword">break</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: -  字符串也可以判断</span></span><br><span class="line"><span class="keyword">let</span> jack = <span class="string">"jack"</span></span><br><span class="line"><span class="keyword">switch</span> jack &#123;</span><br><span class="line"><span class="keyword">case</span> <span class="string">"jack"</span>:</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"jack"</span>)</span><br><span class="line"><span class="keyword">default</span>:</span><br><span class="line">    <span class="keyword">break</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - Switch区间判断</span></span><br><span class="line"><span class="keyword">switch</span> num1 &#123;</span><br><span class="line"><span class="keyword">case</span> <span class="number">1</span>...<span class="number">49</span>:</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"666"</span>)</span><br><span class="line"><span class="keyword">case</span> <span class="number">50</span>...<span class="number">100</span>:</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"111"</span>)</span><br><span class="line"><span class="keyword">default</span>:</span><br><span class="line">    <span class="keyword">break</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 元组在Switch中 _下划线忽略某个值</span></span><br><span class="line"><span class="keyword">let</span> point = (<span class="number">1</span>,<span class="number">1</span>)</span><br><span class="line"><span class="keyword">switch</span> point &#123;</span><br><span class="line"><span class="keyword">case</span> (<span class="number">_</span>,<span class="number">0</span>):</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"在Y轴上"</span>)</span><br><span class="line"><span class="keyword">case</span>(<span class="number">0</span>,<span class="number">_</span>):</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"在X周上"</span>)</span><br><span class="line"><span class="keyword">case</span> (-<span class="number">2</span>...<span class="number">2</span>,-<span class="number">2</span>...<span class="number">2</span>):</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"在正方形中"</span>)</span><br><span class="line"><span class="keyword">default</span>:</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"在外面"</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">let</span> point2 = (<span class="number">2</span>,<span class="number">0</span>)</span><br><span class="line"><span class="keyword">switch</span> point2 &#123;</span><br><span class="line"><span class="keyword">case</span> (<span class="keyword">let</span> x,<span class="number">0</span>):</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"其中的0符合条件 , 其中的一个符合就可以了2赋值给X = \(x)"</span>)</span><br><span class="line"><span class="keyword">case</span> (<span class="number">0</span>,<span class="keyword">let</span> y):</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"需要的时候 let 也可以改成 var 来修改值"</span>)</span><br><span class="line"><span class="keyword">default</span>:</span><br><span class="line">    <span class="keyword">break</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - Swicht - where</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">switch</span> point2 &#123;</span><br><span class="line"><span class="keyword">case</span> <span class="keyword">let</span> (x,y) <span class="keyword">where</span> x == y:</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"这种情况下要是不写where,其中的x,y没有固定值,所以会符合条件,写了where之后 XY才会符合掉件"</span>)</span><br><span class="line"><span class="keyword">case</span> <span class="keyword">let</span> (x,y) <span class="keyword">where</span> x - <span class="number">2</span> == y:</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"---"</span>)</span><br><span class="line"><span class="keyword">default</span>:</span><br><span class="line">    <span class="keyword">break</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="Function"><a href="#Function" class="headerlink" title="Function"></a>Function</h4><p><strong>隐试返回</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">sum</span><span class="params">(value : Int , addValue : Int)</span></span> -&gt; <span class="type">Int</span> &#123;</span><br><span class="line">    value + addValue</span><br><span class="line"><span class="comment">//  如果函数体是一个单一表达式 那么函数会隐式返回这个表达式 Return可以省略</span></span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>多返回值-元组</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - &lt;&lt; &gt;&gt; 移位运算符  右移是1位是取一半 10&gt;&gt;1 = 5; 10&gt;&gt; 2 = 2, 相反左移 5&lt;&lt;1 = 10,10&lt;&lt;1 = 20</span></span><br><span class="line"><span class="comment">// MARK: - 多返回值-元组</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">operationF</span><span class="params">(value1 : Int,value2 : Int)</span></span> -&gt; (sum : <span class="type">Int</span>,difference : <span class="type">Int</span>,average : <span class="type">Int</span>) &#123;</span><br><span class="line">    (value1 + value2,value1 - value2,(value1 + value2)&gt;&gt;<span class="number">1</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>参数标签</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 函数参数标签 at 属于参数标签  作用调用方 看起来好理解goToWork(at: "08:00") 像是英文句子,而函数里面使用就是time,很明显写函数的时候一看就是时间,要是函数里面也是at的话会很乱</span></span><br><span class="line"><span class="keyword">fileprivate</span> <span class="function"><span class="keyword">func</span> <span class="title">goToWork</span><span class="params">(at time : String)</span></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"this time is \(time)"</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>省略标签</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 也可以用_下划线省略标签 goToWork("08:00")</span></span><br><span class="line"><span class="keyword">fileprivate</span> <span class="function"><span class="keyword">func</span> <span class="title">goToWork</span><span class="params">(<span class="number">_</span> time : String)</span></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"this time is \(time)"</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>参数默认值</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 参数默认值 checkName(age: 1)</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">checkName</span><span class="params">(name : String = <span class="string">"默认值"</span>,age : Int)</span></span> &#123;</span><br><span class="line">    <span class="built_in">print</span>(name)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>可变参数</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 可变参数 var age = sum(13,11,43,12)</span></span><br><span class="line"><span class="comment">// MARK: - 一个函数最多只能有一个可变参数,紧跟在可变参数后面的参数不能省略参数标签</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">sum</span><span class="params">(<span class="number">_</span> numbers : Int...)</span></span>-&gt;<span class="type">Int</span>&#123;</span><br><span class="line">    <span class="keyword">var</span> total = <span class="number">0</span></span><br><span class="line">    <span class="keyword">for</span> age <span class="keyword">in</span> numbers&#123;</span><br><span class="line">        total += age</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">return</span> total</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>输入输出参数inout</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 输入输出参数-函数内部修改外部参数的值, inout参数不能有可变参,inout参数不能有默认值</span></span><br><span class="line"><span class="comment">// var value = 10</span></span><br><span class="line"><span class="comment">// sum(value: &amp;value)</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">sum</span><span class="params">(value : <span class="keyword">inout</span> Int)</span></span>&#123;</span><br><span class="line">    value = <span class="number">20</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>函数重载</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">// MARK: - 函数重载-重载和重写的区别-重载不牵扯继承,重写是跟继承有关系的</span><br><span class="line">// MARK: - 函数名称相同</span><br><span class="line">// MARK: - 参数个数不同 || 参数类型不同 || 参数表表不同</span><br><span class="line">// MARK: - 函数重载跟返回值类型不关</span><br></pre></td></tr></table></figure>
<p><strong>typealias</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">typealias</span> <span class="type">Byte</span> = <span class="type">Int8</span></span><br><span class="line"><span class="keyword">typealias</span> <span class="type">Short</span> = <span class="type">Int16</span></span><br><span class="line"><span class="keyword">typealias</span> <span class="type">Long</span> = <span class="type">Int64</span></span><br><span class="line"><span class="keyword">typealias</span> <span class="type">Date</span> = (year : <span class="type">Int</span>,month : <span class="type">Int</span>,day : <span class="type">Int</span>)</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">test</span><span class="params">(<span class="number">_</span> date : Date)</span></span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(date.year)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">typealias</span> <span class="type">Func</span> = (<span class="type">Int</span> ,<span class="type">Int</span>) -&gt; <span class="type">Int</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">test1</span> <span class="params">(t : Func)</span></span>-&gt;()&#123;  <span class="comment">//   Swift中void等价于空元组</span></span><br><span class="line">    </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h4 id="Enum"><a href="#Enum" class="headerlink" title="Enum"></a>Enum</h4><p><strong>enum</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">enum Direction &#123;</span><br><span class="line">    case north</span><br><span class="line">    case south</span><br><span class="line">    case east</span><br><span class="line">    case wast</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>标签</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">enum Score &#123;</span><br><span class="line">    case points(fenshu : Int)</span><br><span class="line">    case grade(Character)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">var score = Score.points(fenshu: 90)</span><br><span class="line">score = .grade(&quot;A&quot;)</span><br></pre></td></tr></table></figure>
<p><strong>关联值Associated Values</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">enum</span> <span class="title">Datee</span> </span>&#123;</span><br><span class="line">    <span class="keyword">case</span> digit(year: <span class="type">Int</span>,month: <span class="type">Int</span>,day: <span class="type">Int</span>)</span><br><span class="line">    <span class="keyword">case</span> string(<span class="type">String</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// MARK: - Associated Values 关联值</span></span><br><span class="line"><span class="comment">// MARK: - 有时会将枚举的成员值跟其他类型的关联存储在一起,会非常有用</span></span><br><span class="line"><span class="comment">// MARK: - 必要是let也可以改为var</span></span><br><span class="line"><span class="keyword">var</span> date = <span class="type">Datee</span>.digit(year : <span class="number">2019</span>,month : <span class="number">06</span>,day : <span class="number">03</span>)</span><br><span class="line">date = .string(<span class="string">"2019-06-03"</span>)</span><br><span class="line"></span><br><span class="line"><span class="keyword">switch</span> date &#123;</span><br><span class="line"><span class="keyword">case</span> .digit(<span class="keyword">let</span> year,<span class="keyword">let</span> month,<span class="keyword">var</span> day):</span><br><span class="line">    day += <span class="number">1</span></span><br><span class="line">    <span class="built_in">print</span>(year,month,day)</span><br><span class="line"><span class="keyword">case</span> <span class="keyword">let</span> .string(value):</span><br><span class="line">    <span class="built_in">print</span>(value)</span><br><span class="line"><span class="keyword">default</span>:</span><br><span class="line">    <span class="keyword">break</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>原始值 - Row Values</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">注意:一旦设置成原始值就不可修改, 而关联值就不同了,关联值枚举值是可以改的</span><br><span class="line">enum PokerSuit : Character &#123;</span><br><span class="line">    case spade = &quot;♠️&quot;</span><br><span class="line">    case headrt = &quot;♥️&quot;</span><br><span class="line">    case diamond = &quot;♦️&quot;</span><br><span class="line">    case clud = &quot;♣️&quot;</span><br><span class="line">&#125;</span><br><span class="line">// MARK: - 原始值</span><br><span class="line">var suit = PokerSuit.spade</span><br><span class="line">print(suit)</span><br><span class="line">print(suit.rawValue) // 打印原始值</span><br><span class="line">print(PokerSuit.spade.rawValue) // 打印原始值</span><br></pre></td></tr></table></figure>
<p><strong>隐式原始值</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 隐式原始值 - 如果枚举的原始值类型是Int,String,Swift会自动分配原始值</span></span><br><span class="line"><span class="class"><span class="keyword">enum</span> <span class="title">Direction1</span> : <span class="title">String</span> </span>&#123;</span><br><span class="line">    <span class="keyword">case</span> north = <span class="string">"north"</span></span><br><span class="line">    <span class="keyword">case</span> south = <span class="string">"south"</span></span><br><span class="line">    <span class="keyword">case</span> east = <span class="string">"east"</span></span><br><span class="line">    <span class="keyword">case</span> wast = <span class="string">"wast"</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">// MARK: - 隐式原始值 - 如果枚举的原始值类型是Int,String,Swift会自动分配原始值</span></span><br><span class="line"><span class="comment">//enum Direction1 : String &#123; 这个跟上面的Enum是一样的 名称什么样值也是一样的</span></span><br><span class="line"><span class="comment">//    case north, south, east, wast 如果是Int类型的那么 从前面开始 0 1 2 3 4 ...</span></span><br><span class="line"><span class="comment">//  如果自己制定了原始值 north = 1, east = 4 那么就是 south = 2 wast = 5</span></span><br><span class="line"><span class="comment">//&#125;</span></span><br></pre></td></tr></table></figure>
<p><strong>递归枚举</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 枚举递归</span></span><br><span class="line"><span class="keyword">indirect</span> <span class="class"><span class="keyword">enum</span> <span class="title">ArithExpr</span></span>&#123;</span><br><span class="line">    <span class="keyword">case</span> number (<span class="type">Int</span>)</span><br><span class="line">    <span class="keyword">case</span> sum(<span class="type">ArithExpr</span>,<span class="type">ArithExpr</span>)</span><br><span class="line">    <span class="keyword">case</span> difference(<span class="type">ArithExpr</span>,<span class="type">ArithExpr</span>)</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// MARK: - 枚举递归的小例子</span></span><br><span class="line"><span class="keyword">let</span> five = <span class="type">ArithExpr</span>.number(<span class="number">5</span>)</span><br><span class="line"><span class="keyword">let</span> four = <span class="type">ArithExpr</span>.number(<span class="number">4</span>)</span><br><span class="line"><span class="keyword">let</span> tow = <span class="type">ArithExpr</span>.number(<span class="number">2</span>)</span><br><span class="line"><span class="keyword">let</span> sum = <span class="type">ArithExpr</span>.sum(five, four)</span><br><span class="line"><span class="keyword">let</span> difference = <span class="type">ArithExpr</span>.difference(sum, tow)</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">// MARK: - 枚举递归的小例子</span></span><br><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">calculate</span><span class="params">(<span class="number">_</span> expr : ArithExpr)</span></span> -&gt; <span class="type">Int</span>&#123;</span><br><span class="line">    <span class="keyword">switch</span> expr &#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">case</span> <span class="keyword">let</span> .number(value):</span><br><span class="line">        <span class="keyword">return</span> value</span><br><span class="line"></span><br><span class="line">    <span class="keyword">case</span> <span class="keyword">let</span> .sum(<span class="keyword">left</span>, <span class="keyword">right</span>):</span><br><span class="line">        <span class="keyword">return</span> calculate(<span class="keyword">left</span>) + calculate(<span class="keyword">right</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">case</span> <span class="keyword">let</span> .difference(<span class="keyword">left</span>, <span class="keyword">right</span>):</span><br><span class="line">        <span class="keyword">return</span> calculate(<span class="keyword">left</span>) - calculate(<span class="keyword">right</span>)</span><br><span class="line"></span><br><span class="line">    <span class="keyword">default</span>:</span><br><span class="line">        <span class="keyword">break</span></span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>MemoryLayout</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">enum</span> <span class="title">Password</span> </span>&#123;</span><br><span class="line">    <span class="keyword">case</span> number(<span class="type">Int</span>, <span class="type">Int</span>, <span class="type">Int</span>, <span class="type">Int</span>)</span><br><span class="line">    <span class="keyword">case</span> other</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> pwd = <span class="type">Password</span>.number(<span class="number">6</span>, <span class="number">1</span>, <span class="number">3</span>, <span class="number">7</span>)</span><br><span class="line">pwd = .other</span><br><span class="line"><span class="type">MemoryLayout</span>&lt;<span class="type">Password</span>&gt;.size     <span class="comment">// 33 实际占用的内存</span></span><br><span class="line"><span class="type">MemoryLayout</span>&lt;<span class="type">Password</span>&gt;.<span class="built_in">stride</span>   <span class="comment">// 40 内存对齐占用的内存</span></span><br><span class="line"><span class="type">MemoryLayout</span>&lt;<span class="type">Password</span>&gt;.alignment    <span class="comment">// 8 内从对齐参数</span></span><br></pre></td></tr></table></figure>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">注意:这里存储空间为什么是<span class="number">1</span>,而不是<span class="type">Int</span> 的 <span class="number">8</span>,是因为枚举是原始值,因为那个<span class="number">2000</span>不会存储在s那个变量里面,<span class="class"><span class="keyword">enum</span>用一个字节判断 <span class="title">spring</span> 还是 <span class="title">summer</span> 还是 <span class="title">autumn</span> 还是 <span class="title">winter</span>,就是说固定的不可修改,这样就可以用一个字节判断,它只是知道2000就到表这<span class="title">spring</span></span></span><br><span class="line"><span class="class"><span class="title">enum</span> <span class="title">Season</span> : <span class="title">Int</span></span>&#123;</span><br><span class="line">	<span class="keyword">case</span> spring = <span class="number">2000</span>, summer, autumn, winter</span><br><span class="line">&#125;</span><br><span class="line"><span class="keyword">var</span> s = <span class="type">Season</span>.spring</span><br><span class="line"><span class="type">MemoryLayout</span>&lt;<span class="type">Season</span>&gt;.size     <span class="comment">// 1 </span></span><br><span class="line"><span class="type">MemoryLayout</span>&lt;<span class="type">Season</span>&gt;.<span class="built_in">stride</span>   <span class="comment">// 1</span></span><br><span class="line"><span class="type">MemoryLayout</span>&lt;<span class="type">Season</span>&gt;.alignment    <span class="comment">// 1</span></span><br><span class="line"></span><br><span class="line"><span class="comment">//向上面的var date = Datee.digit(year : 2019,month : 06,day : 03) 关联值会存储在date这个变量里面</span></span><br></pre></td></tr></table></figure>
<p><strong>Guard</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">guard</span> <span class="keyword">let</span> number = <span class="type">Int</span>(<span class="string">"123"</span>) <span class="keyword">else</span> &#123;<span class="built_in">print</span>(<span class="string">"转换失败"</span>); <span class="keyword">return</span>&#125;</span><br><span class="line"><span class="built_in">print</span>(<span class="string">"\(number)转换成功"</span>)</span><br></pre></td></tr></table></figure>
<p><strong>可选绑定</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//  可选项绑定 - 缺点number只能在&#123;&#125;内部使用,用guard的话number在外面也可以使用</span></span><br><span class="line"><span class="keyword">if</span> <span class="keyword">let</span> number = <span class="type">Int</span>(<span class="string">"123"</span>)&#123;</span><br><span class="line">    <span class="built_in">print</span>(number)</span><br><span class="line">&#125;<span class="keyword">else</span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"转换失败"</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>多个可选绑定</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">if</span> <span class="keyword">let</span> first = <span class="type">Int</span>(<span class="string">"4"</span>)&#123;</span><br><span class="line">    <span class="keyword">if</span> <span class="keyword">let</span> second = <span class="type">Int</span>(<span class="string">"2"</span>) &#123;</span><br><span class="line">        <span class="keyword">if</span> first &lt; second &amp;&amp; second &lt; <span class="number">100</span> &#123;</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">"\(first) &lt; \(second)"</span>)</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">        </span><br><span class="line"><span class="comment">//  等价于 可选项绑定牵扯到多个用逗号隔开</span></span><br><span class="line"><span class="keyword">if</span> <span class="keyword">let</span> first = <span class="type">Int</span>(<span class="string">"4"</span>), <span class="keyword">let</span> second = <span class="type">Int</span>(<span class="string">"2"</span>),first &lt; second &amp;&amp; second &lt; <span class="number">100</span>&#123;</span><br><span class="line">    <span class="built_in">print</span>(<span class="string">"\(first) &lt; \(second)"</span>)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>空合并运算符</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// MARK: - 空合并运算符</span></span><br><span class="line"><span class="keyword">var</span> age : <span class="type">Int</span>?</span><br><span class="line"><span class="keyword">let</span> value = <span class="number">23</span></span><br><span class="line"><span class="keyword">let</span> num = age ?? value <span class="comment">//   num的类型由value而定如果 value是可选类型的那么num最终是可选类型的,如果value不是可选类型的那么num是不是可选类型的(如果age有值,并且value不是可选类型的那么会对age解包)</span></span><br><span class="line"><span class="comment">// MARK: - 多个空合并云算符也是一样看最右边的</span></span><br></pre></td></tr></table></figure>
<h4 id="枚举内存"><a href="#枚举内存" class="headerlink" title="枚举内存"></a>枚举内存</h4><p><strong>关联值枚举 - 内存</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">enum</span> <span class="title">Test</span> </span>&#123;</span><br><span class="line">    <span class="keyword">case</span> test1(<span class="type">Int</span>,<span class="type">Int</span>,<span class="type">Int</span>)</span><br><span class="line">    <span class="keyword">case</span> test2(<span class="type">Int</span>,<span class="type">Int</span>)</span><br><span class="line">    <span class="keyword">case</span> test3(<span class="type">Int</span>)</span><br><span class="line">    <span class="keyword">case</span> test4(<span class="type">Bool</span>)</span><br><span class="line">    <span class="keyword">case</span> test5</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//	内存情况</span></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> e = .test2(3, 4)</span></span><br><span class="line"><span class="comment"> 03 00 00 00 00 00 00 00</span></span><br><span class="line"><span class="comment"> 04 00 00 00 00 00 00 00</span></span><br><span class="line"><span class="comment"> 00 00 00 00 00 00 00 00</span></span><br><span class="line"><span class="comment"> 01 00 00 00 00 00 00 00</span></span><br><span class="line"><span class="comment"> 其中3和4各占8个字节,空出8个字节后的01代表着那个一个枚举值01也就是case test2(Int,Int)</span></span><br><span class="line"><span class="comment">*/</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> e = .test3(1)</span></span><br><span class="line"><span class="comment"> 01 00 00 00 00 00 00 00</span></span><br><span class="line"><span class="comment"> 00 00 00 00 00 00 00 00</span></span><br><span class="line"><span class="comment"> 00 00 00 00 00 00 00 00</span></span><br><span class="line"><span class="comment"> 02 00 00 00 00 00 00 00</span></span><br><span class="line"><span class="comment"> 其中的01占据8个字节.test3(1),02是代表这    case test3(Int)</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="comment">//	注意:如果只有一个case那么就没有成员值也就是 上面的02是没有的 因为不需要辨别</span></span><br><span class="line"><span class="keyword">var</span> e = <span class="type">Test</span>.test1(<span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>)</span><br><span class="line"><span class="built_in">print</span>(<span class="type">Mems</span>.ptr(ofVal: &amp;e))</span><br><span class="line">e = .test2(<span class="number">3</span>, <span class="number">4</span>)</span><br><span class="line">e = .test3(<span class="number">1</span>)</span><br><span class="line">e = .test5</span><br><span class="line"></span><br><span class="line"><span class="built_in">print</span>(<span class="type">MemoryLayout</span>&lt;<span class="type">Test</span>&gt;.size)			<span class="number">25</span>取出占用内存最大的<span class="keyword">case</span>,以后不管你是哪一个<span class="keyword">case</span>共用这块内存,多出一个字节成员值</span><br><span class="line"><span class="built_in">print</span>(<span class="type">MemoryLayout</span>&lt;<span class="type">Test</span>&gt;.<span class="built_in">stride</span>)		<span class="number">32</span></span><br><span class="line"><span class="built_in">print</span>(<span class="type">MemoryLayout</span>&lt;<span class="type">Test</span>&gt;.alignment) <span class="number">8</span> </span><br><span class="line"></span><br><span class="line"><span class="keyword">switch</span> e &#123;</span><br><span class="line">        <span class="keyword">case</span> <span class="keyword">let</span> .test1(v1, v2, v3):</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">"test1"</span>)</span><br><span class="line">            </span><br><span class="line">        <span class="keyword">case</span> <span class="keyword">let</span> .test2(v1, v2):</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">"test2"</span>)</span><br><span class="line">            </span><br><span class="line">        <span class="keyword">case</span> <span class="keyword">let</span> .test3(v1):</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">"test3"</span>)</span><br><span class="line">            </span><br><span class="line">        <span class="keyword">case</span> <span class="keyword">let</span> .test4(v1):</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">"test4"</span>)</span><br><span class="line">            </span><br><span class="line">        <span class="keyword">case</span> <span class="keyword">let</span> .test5:</span><br><span class="line">            <span class="built_in">print</span>(<span class="string">"test5"</span>)</span><br><span class="line">        <span class="keyword">default</span>:</span><br><span class="line">            <span class="keyword">break</span></span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//	Switch是怎么判断的 - 利用成员值判断,如果是true 再把值灌给v1,v2...</span></span><br></pre></td></tr></table></figure>
<p><strong>简单枚举 - 内存</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">enum</span> <span class="title">Test_Enum</span></span>&#123;</span><br><span class="line">    <span class="keyword">case</span> t1,t2,t3,t4,t5</span><br><span class="line">&#125;</span><br><span class="line"><span class="built_in">print</span>(<span class="type">MemoryLayout</span>&lt;<span class="type">Test_Enum</span>&gt;.size)			<span class="number">1</span></span><br><span class="line"><span class="built_in">print</span>(<span class="type">MemoryLayout</span>&lt;<span class="type">Test_Enum</span>&gt;.<span class="built_in">stride</span>)		<span class="number">1</span></span><br><span class="line"><span class="built_in">print</span>(<span class="type">MemoryLayout</span>&lt;<span class="type">Test_Enum</span>&gt;.alignment)<span class="number">1</span></span><br><span class="line">只占用一个字节<span class="number">01</span> = t1, <span class="number">02</span> = t2所以这种枚举可以写 <span class="number">0</span>~<span class="number">256</span> <span class="number">0</span>~<span class="type">FF</span></span><br></pre></td></tr></table></figure>
<h4 id="结构体和类"><a href="#结构体和类" class="headerlink" title="结构体和类"></a>结构体和类</h4><p><strong>结构体</strong> </p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Point</span> </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> x : <span class="type">Int</span> = <span class="number">0</span></span><br><span class="line">    <span class="keyword">var</span> y : <span class="type">Int</span> = <span class="number">0</span></span><br><span class="line">  <span class="comment">//	结构体里面也是可以写函数的</span></span><br><span class="line">  <span class="function"><span class="keyword">func</span> <span class="title">test</span><span class="params">()</span></span>&#123;</span><br><span class="line">    </span><br><span class="line">  &#125;</span><br><span class="line">&#125;</span><br><span class="line">    </span><br><span class="line"><span class="comment">//	如果上面的xy没有初始值 则只有Point(x: 1, y: 1)这个初始化方法, 如果只有X有初始值,会有这初始化方法Point(x: 1) 相对一样的</span></span><br><span class="line"><span class="comment">//var x : Int? var y : Int? 也是可以的</span></span><br><span class="line"><span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">viewDidLoad</span><span class="params">()</span></span> &#123;</span><br><span class="line">    <span class="keyword">super</span>.viewDidLoad()</span><br><span class="line">    <span class="number">_</span> = <span class="type">Point</span>(x: <span class="number">1</span>, y: <span class="number">1</span>)</span><br><span class="line">    <span class="number">_</span> = <span class="type">Point</span>(y: <span class="number">1</span>)</span><br><span class="line">    <span class="number">_</span> = <span class="type">Point</span>(x: <span class="number">1</span>)</span><br><span class="line">    <span class="number">_</span> = <span class="type">Point</span>()</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>自定义初始化器-如果自定义了初始化器那么编译器不会自动生成其他初始化器-也是就是说上面的那三个初始化器没了</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Point</span> </span>&#123;</span><br><span class="line">    <span class="keyword">var</span> x : <span class="type">Int</span> = <span class="number">0</span></span><br><span class="line">    <span class="keyword">var</span> y : <span class="type">Int</span> = <span class="number">0</span></span><br><span class="line">    <span class="keyword">init</span>(x: <span class="type">Int</span> ,y: <span class="type">Int</span>) &#123;</span><br><span class="line"><span class="comment">// x: Int ,y: Int 参数里面传的不是 x和y的话 self. 是可以省略的 比如 XY:x = X ,y = Y , _ = Point(X: 1, Y: 1)</span></span><br><span class="line">        <span class="keyword">self</span>.x = x</span><br><span class="line">        <span class="keyword">self</span>.y = y;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">    </span><br><span class="line"><span class="keyword">override</span> <span class="function"><span class="keyword">func</span> <span class="title">viewDidLoad</span><span class="params">()</span></span> &#123;</span><br><span class="line">    <span class="keyword">super</span>.viewDidLoad()</span><br><span class="line">    <span class="number">_</span> = <span class="type">Point</span>(x: <span class="number">1</span>, y: <span class="number">1</span>)		<span class="comment">//	自定义初始化器</span></span><br><span class="line">    <span class="number">_</span> = <span class="type">Point</span>(y: <span class="number">1</span>)		<span class="comment">//	报错</span></span><br><span class="line">    <span class="number">_</span> = <span class="type">Point</span>(x: <span class="number">1</span>)		<span class="comment">//	报错</span></span><br><span class="line">    <span class="number">_</span> = <span class="type">Point</span>()				<span class="comment">//	报错</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>类-类是不会像结构体自动生成初始化器的-如果类的成员有默认值会生成无惨的初始化</strong></p>
<p><strong>Class和Struct的区别:结构体和枚举是值类型,Class是指针类型也是引用类型</strong></p>
<p><strong>值类型是赋值是深拷贝—Swift标准库中为了提升性能String,Array,Dictionary,Set采取了Copy On Write </strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="type">Copy</span> <span class="type">On</span> <span class="type">Write</span> </span><br><span class="line"><span class="keyword">var</span> s1 = <span class="string">"abc"</span></span><br><span class="line"><span class="keyword">var</span> s2 = s1</span><br><span class="line"><span class="comment">//	如果后面 s1和s2 都不会有修改的话他会是浅拷贝,如果会修改自动为深拷贝</span></span><br></pre></td></tr></table></figure>
<p><strong>引用类型赋值给var,let或者给函数参数,是将内存地址拷贝一份</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">规律:</span><br><span class="line">内存地址格式为: 0x4bd(%rip),一般是全局变量,全局区(数据段)</span><br><span class="line">内存地址格式为: 0x78(%rbp),一般是局部变量,栈空间</span><br><span class="line">内存地址格式为: 0x78(%rbp),一般是堆空间</span><br></pre></td></tr></table></figure>
<h4 id="闭包表达式"><a href="#闭包表达式" class="headerlink" title="闭包表达式"></a>闭包表达式</h4><p><strong>在Swift中,可以动过func定义一个函数,也可以通过闭包表达式顶一个函数</strong></p>
<figure class="highlight swift"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">func</span> <span class="title">sum</span> <span class="params">(<span class="number">_</span> v1: Int ,<span class="number">_</span> v2: Int)</span></span> -&gt;<span class="type">Int</span>&#123;v1 + v2&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">var</span> fn = &#123;</span><br><span class="line">    (v1: <span class="type">Int</span>, v2: <span class="type">Int</span>) -&gt; <span class="type">Int</span> <span class="keyword">in</span></span><br><span class="line">    <span class="keyword">return</span> v1 + v2</span><br><span class="line">&#125;</span><br><span class="line">fn(<span class="number">10</span>,<span class="number">20</span>)</span><br><span class="line">&#123;</span><br><span class="line">  (参数列表) -&gt; 返回值类型 <span class="keyword">in</span> </span><br><span class="line">  函数体代码</span><br><span class="line">&#125;</span><br><span class="line"><span class="comment">//	也可以</span></span><br><span class="line">&#123;</span><br><span class="line">    (v1: <span class="type">Int</span>, v2: <span class="type">Int</span>) -&gt; <span class="type">Int</span> <span class="keyword">in</span></span><br><span class="line">    <span class="keyword">return</span> v1 + v2</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p><strong>简写</strong></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/02/19/Function/" rel="next" title="Function">
                <i class="fa fa-chevron-left"></i> Function
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/07/17/数据结构与算法/" rel="prev" title="数据结构与算法-01">
                数据结构与算法-01 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  
    <div class="comments" id="comments">
    </div>
  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            Table of Contents
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            Overview
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/images/10.png"
                alt="Erhqe" />
            
              <p class="site-author-name" itemprop="name">Erhqe</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">70</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                
                  <span class="site-state-item-count">31</span>
                  <span class="site-state-item-name">categories</span>
                
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">1</span>
                  <span class="site-state-item-name">tags</span>
                
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#条件语句"><span class="nav-number">1.</span> <span class="nav-text">条件语句</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#For-In"><span class="nav-number">1.0.1.</span> <span class="nav-text">For In</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#Switch"><span class="nav-number">1.0.2.</span> <span class="nav-text">Switch</span></a></li></ol></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Function"><span class="nav-number">2.</span> <span class="nav-text">Function</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#Enum"><span class="nav-number">3.</span> <span class="nav-text">Enum</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#枚举内存"><span class="nav-number">4.</span> <span class="nav-text">枚举内存</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#结构体和类"><span class="nav-number">5.</span> <span class="nav-text">结构体和类</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#闭包表达式"><span class="nav-number">6.</span> <span class="nav-text">闭包表达式</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Erhqe</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Muse</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  










  <script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
  <script src="//unpkg.com/valine/dist/Valine.min.js"></script>
  
  <script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: false,
        appId: 'TiAY2J24ECwQH9uLYsoJpgIK-gzGzoHsz',
        appKey: 'Y9PiVrPXVmfNsv4Aa6cPsADG',
        placeholder: 'Just go go',
        avatar:'mm',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script>



  





  

  

  

  
  

  

  

  

</body>
</html>
